#ifndef _CODER_IMP_
#define _CODER_IMP_

#include "Coder.h"
#include <vector>
#include <map>

struct DictItemExt
{
	DictItem _item;
	int _count;
};

struct HuffmanNode
{
	HuffmanNode() { next = 0; left = 0; right = 0; _itemExt = 0; }
	DictItemExt* _itemExt;
	HuffmanNode *next, *left, *right;
	int count;
};

class CoderImp : public Coder
{
public:
	CoderImp(void);
	~CoderImp(void);
	
	virtual void Input(BYTE data);
	virtual void Parse();
	virtual void InputBlock(BYTE* data, int dataSize);
	virtual bool GetNextDictItem(DictItem* di);
	virtual bool GetNextCode(DataCode* oc);

	virtual int GetDataCount();
	virtual int GetDictItemCount();

private:
	BYTE* _dataBlock;
	int _dataBlockSize;
	int _dataIter;
	int _dictItemCount;
	int _dictItemAllCount;

	std::vector<DictItemExt> _dictionary;
	std::map<DictData, int> _counter;
	std::map<DictData, DataCode> _outmap;

	HuffmanNode *_head, *_cur;
};

#endif